<?php


namespace app\admin\model;

class ListsFieldsDisplay extends Base
{
    /**
     * Desc: 保存用户指定后端列表页显示字段
     * User: 苏鹏
     * Date: 2023/10/23
     * Time: 15:49
     * @return void
     */
    public function setListFields(string $field, int $user_id, string $controller)
    {
        //为空清空数据表内容
        if(empty($field))
        {
            $this->where('user_id','=', $user_id)->where('controller', '=', $controller)->delete();
        }else{
            $list_fields = $this->where('user_id', $user_id)->where('controller', $controller)->value('fields');
            //保存用户显示后端显示字段
            $data = [
                'controller' => $controller,
                'fields' => $field,
                'user_id' => $user_id
            ];
            //存在修改，不存在添加
            if(empty($list_fields))
            {
                $this->insert($data);
            }else{
                $this->where('user_id','=', $user_id)->where('controller', '=', $controller)->update($data);
            }
        }
    }
}